/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

// returns list of user groups
function getUserGroups() {
	return $.Deferred( function(defObj){
		FB.api(
			"/me/groups",
			function(response) {
				if (response && !response.error)
					defObj.resolve(response);
				else
					defObj.reject( {
						'msg' : 'Failed to fetch gruop list!',
						'response' : response
					});
			}
		);
	}).fail( function(e){
		// login failure handler
		document.getElementById('status').innerHTML = 'API Call Failure: ' + e.msg;
	}).promise();
}

function getUserGroupEvents(group){
	return $.Deferred( function(defObj){
		FB.api(
			"/" + group.id + "/events",
			function(response) {
				if (response && !response.error)
					// success!
					defObj.resolve( response.data ); // return retrieved data...
				else
					defObj.reject( {
						'msg' : "Failed for group " + group.name,
						'response' : response
					});
			}
		);
	}).fail( function(e){
		// login failure handler
		document.getElementById('status').innerHTML = 'API Call Failure: ' + e.msg;
	}).promise();
}

